package com.nowcoder.Offer.Dp;

import org.junit.Test;


/**
 * 连续子数组的最大和
 */
public class MaxArraySum {
    public int FindGreatestSumOfSubArray(int[] array) {
        int cur = array[0];
        int ans = Integer.MIN_VALUE;
        for(int i=1; i<array.length; i++){
            cur = Math.max(cur + array[i] , array[i]);
            ans = Math.max(ans,cur);
        }
        return ans;
    }

    @Test
    public void test(){
        int[] arr = {-2,-8,-1,-5,-9};
        System.out.println(FindGreatestSumOfSubArray(arr));
    }
}
